package cn.com.blueInfo.bpm.system.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.system.request.RoleDTO;
import cn.com.blueInfo.bpm.system.response.RoleVO;
import cn.com.blueInfo.bpm.system.service.RoleService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 角色表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:37:55
 */
@Tag(name = "角色 接口")
@RestController
@RequestMapping("/system/role")
public class RoleController extends BaseController {

    @Autowired
    private RoleService roleService;

    /**
     * 新建角色
     * @param roleDTO 角色参数
     * @return ResultInfo
     */
    @Operation(summary = "新增角色")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createRole(
            @Validated({Create.class, Default.class}) @RequestBody RoleDTO roleDTO) {
        return roleService.addRole(roleDTO);
    }

    /**
     * 批量新建角色
     * @param roleDTOList 角色参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建角色")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateRole(
            @Validated({Create.class, Default.class}) @RequestBody List<RoleDTO> roleDTOList) {
        return roleService.batchAddRole(roleDTOList);
    }

    /**
     * 根据ID删除角色
     * @param roleId 角色ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除角色")
    @DeleteMapping("/removeInfo/{roleId}")
    public ResultInfo<Integer> deleteRoleById(
            @Parameter(name = "ID") @PathVariable Long roleId) {
        return roleService.removeRole(roleId);
    }

    /**
     * 批量根据ID删除角色
     * @param roleIdList 角色ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除角色")
    @DeleteMapping("/removeInfoList/{roleIdList}")
    public ResultInfo<Integer> batchDeleteRoleById(
            @Parameter(name = "ID") @PathVariable List<Long> roleIdList) {
        return roleService.batchRemoveRole(roleIdList);
    }

    /**
     * 根据ID全量更新角色
     * @param roleId 角色ID
     * @param roleDTO 角色参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新角色")
    @PutMapping("/modifyInfo/{roleId}")
    public ResultInfo<Integer> updateRoleFull(
            @Parameter(name = "ID") @PathVariable Long roleId,
            @Validated({Update.class, Default.class}) @RequestBody RoleDTO roleDTO) {
        validateUpdateId(roleId, roleDTO.getId());
        return roleService.modifyRole(roleDTO);
    }

    /**
     * 根据ID部分更新角色
     * @param roleId 角色ID
     * @param roleUpdatePartialDTO 角色参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新角色")
    @PatchMapping("/modifyPartialInfo/{roleId}")
    public ResultInfo<Integer> updateRolePartial(
            @Parameter(name = "ID") @PathVariable Long roleId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            RoleDTO.UpdatePartialDTO roleUpdatePartialDTO) {
        validateUpdateId(roleId, roleUpdatePartialDTO.getId());
        return roleService.modifyRolePartial(roleUpdatePartialDTO);
    }

    /**
     * 根据ID查询角色
     * @param roleId 角色ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询角色")
    @GetMapping("/getInfo/{roleId}")
    public ResultInfo<RoleVO> getRoleById(
            @Parameter(name = "ID") @PathVariable Long roleId) {
        return roleService.queryRoleById(roleId);
    }

    /**
     * 分页查询角色
     * @param roleQueryDTO 角色参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询角色")
    @GetMapping("/getInfos")
    public ResultInfo<Page<RoleVO>> getRolePage(
            @Validated RoleDTO.QueryDTO roleQueryDTO) {
        return roleService.queryRolePage(roleQueryDTO);
    }

    /**
     * 根据条件查询角色
     * @param roleQueryDTO 角色参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询角色")
    @GetMapping("/getInfoList")
    public ResultInfo<List<RoleVO>> getRoleList(
            @Validated RoleDTO.QueryDTO roleQueryDTO) {
        return roleService.queryRoleList(roleQueryDTO);
    }

}
